package com.shopoo.oauth.wechat.granter;

import java.util.Map;

import com.shopoo.oauth.domain.valueobject.UserAuth;
import com.shopoo.oauth.wechat.service.CustomUserDetailsService;

import org.springframework.security.oauth2.provider.ClientDetailsService;
import org.springframework.security.oauth2.provider.OAuth2RequestFactory;
import org.springframework.security.oauth2.provider.token.AuthorizationServerTokenServices;

/**
 * @Description
 *
 * @Param 
 * @Return 
 * @Date 2:02 下午 2020/10/29
 * @Author <a href="mailto:android_li@sina.cn">Joe</a>
 */
public class CustomTokenGranter extends AbstractCustomTokenGranter {

    protected CustomUserDetailsService userDetailsService;

    public CustomTokenGranter(CustomUserDetailsService userDetailsService, AuthorizationServerTokenServices tokenServices, ClientDetailsService clientDetailsService, OAuth2RequestFactory requestFactory) {
        super(tokenServices, clientDetailsService, requestFactory, "wechat_oauth2");
        this.userDetailsService = userDetailsService;
    }

    @Override
    protected UserAuth getCustomUser(Map<String, String> parameters) {
        String token = parameters.get("wechat_oauth2");
        return userDetailsService.loadUserByToken(token);
    }

}
